home *** CD-ROM | disk | FTP | other *** search
- These files contain source to two random number generators that I have
- found very useful in my work. I've used the Knuth generator for
- almost a decade now and found it to be very satisfactory. I've been
- using the Marsaglia generator for only about a year, but it also
- works very well. The Marsaglia generator is supposedly (as of a year
- ago) the best random number generator known. It apparently passes
- all known statistical tests for randomness. I say apparently because
- I have not validated it myself, nor have I examined the original
- publication. I'm just repeating the information in random.doc. I
- have no reason not to believe what the people I've cribbed from wrote,
- but don't blame me if you find a problem that I've missed.
-
- The source files for the code I actually use is in RAN.H and RAN.C. A
- sample program illustrating how to use the generators (and to test
- the Marsaglia generator) is in sample.c. You should be able to run
- sample simply by compiling it, ran.c, and linking the two together.
- I've tried to write the code in a very portable way, and I have
- successfully used it under various versions of Microsoft C, cc and
- gcc (on a Sun SPARCstation 2), and Waterloo C and IBM C (on an IBM
- 3090 mainframe). The code from which the Marsaglia generator is
- derived is found in RANDOM.FOR (the original FORTRAN version by David
- LaSalle) and RANDOM-C.C (the C translation by Jim Butler). The
- documentation files that accompanied these is also included (in
- RANDOM.DOC and RANDOM-C.DOC).
-
- Notice that I read the random number seed from a file in each
- execution and that the value of this seed is returned from setup(). I
- do this so that when I am developing a simulation I can duplicate the
- exact pseudo-random sequence that caused a problem.
-
- Notice also that either RAN_KNU or RAN_MAR needs to be explicitly
- defined in RAN.H. RAN_KNU selects the Knuth random number generator.
- RAN_MAR selects the Marsaglia generator.
-
- To test the Marsaglia generator, just compile and link sample.c and
- ran.c as is. When you execute the program you'll be prompted to
- enter two random number seeds. The first number you enter must be
- 1802, and the second must be 9373. After a few seconds a message
- will print out indicating the correct answer and the answer your
- compilation produced. The two should match exactly. If they don't,
- there's some kind of problem. Alternatively, you can create RAND.INT
- as a standard ASCII text file. Then put in a single line that contains
- only the number 614270730.
-
- If the numbers don't match, the most likely cause is that you ran the
- executable once already and the seed read from RAND.INT is not
- 614270730.
-
- Enjoy these tools at your own risk. Although I've been happy with
- their performance, I can't and I won't accept responsibility for any
- pain they might cause you.
-
- -- Kent E. Holsinger
-
-
-
-
- Files included in this package:
-
- Source for Knuth and Marsaglia random number generators
- ran.h
- ran.c
- Source for program to illustrate use of the generators and to test
- sample.c
- Source from which the C version of the Marsaglia generator was derived
- random.for Original Fortran version
- random-c.c C language version
- Documentation
- random.doc
- random-c.doc
-
-